package com.java.web.manageweb.controller.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.java.manage.pojo.TbItem;
import com.java.manage.service.TbItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.swing.text.html.parser.Entity;

/**
 * @ClassName ApiItemController
 * @Description 查询商品内容API
 * @Author Trigger Wu
 * @Date 2018/9/1315:05
 * @Version 1.0
 **/

@RequestMapping("/rest/api/item")
@Controller
public class ApiItemController {
    @Autowired
    private TbItemService itemService;

    /**
     * 根据商品id查询商品数据
     *
     * @param itemId
     * @return
     */
    @RequestMapping(value = "{itemId}", method = RequestMethod.GET)
    public ResponseEntity<TbItem> queryById(@PathVariable("itemId") Long itemId) {
        try {
            EntityWrapper<TbItem>wrapper = new EntityWrapper<TbItem>();
            wrapper.where("id ={0}",itemId);
            TbItem item = itemService.selectOne(wrapper);
            if (null == item) {
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            }
            return ResponseEntity.ok(item);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
